package cn.tuling.beandefinitionreader;

import cn.tuling.beans.User;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class BeanDefinitionReaderTest {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.refresh();

        // AnnotatedBeanDefinitionReader
        AnnotatedBeanDefinitionReader annotatedBeanDefinitionReader = new AnnotatedBeanDefinitionReader(context);
        annotatedBeanDefinitionReader.register(User.class);

        System.out.println(context.getBean("user"));

        //XmlBeanDefinitionReader
        /*XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(context);
        int i = xmlBeanDefinitionReader.loadBeanDefinitions("spring.xml");
        System.out.println(i);
        System.out.println(context.getBean("user"));*/

        /*ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner(context);
        classPathBeanDefinitionScanner.scan("cn.tuling.beans");
        System.out.println(context.getBean("teacher"));
        // NoSuchBeanDefinitionException: No bean named 'user' available
        System.out.println(context.getBean("user")); */
    }

}


